package org.example.demosystem.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.extern.slf4j.Slf4j;
import org.example.demosystem.common.Result;
import org.example.demosystem.entity.Student;
import org.example.demosystem.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@Slf4j
@RestController
@RequestMapping("/student")
public class StudentController {

    /**
     * 学生分页查询
     * */

    @Autowired
    private StudentService studentService;

    @GetMapping
    public Page<Student> getStudentsByPage(@RequestParam(defaultValue = "1") int pageNum,
                                           @RequestParam(defaultValue = "10") int pageSize,
                                           @RequestParam(required = false) String name) {
        return studentService.getStudentsByPage(pageNum, pageSize, name);
    }

    /**
     * 删除学生
     */

    @DeleteMapping("/{sno}")
    public Result deleteStudent(@PathVariable int sno) {
        studentService.removeById(sno);
        return Result.success();
    }

    /**
     * 添加学生
     * */

    @PutMapping
    public Result addStudent(@RequestBody Student student) {
        studentService.save(student);
        return Result.success();
    }



}
